<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="kr.co.insoft.framework.config.Authorities" %>
<c:set var="CONTEXT">${pageContext.request.contextPath}</c:set>
<c:set var="cssUrl">${pageContext.request.contextPath}/resources/css</c:set>
<c:set var="jsUrl">${pageContext.request.contextPath}/resources/js</c:set>
<div class="col-sm-12 page-header custom-page-header">
	<h1><spring:message code="menu.configration.cloudconnection"/></h1>	
</div>
<form:form modelAttribute="connectionEntityModel" role="form" cssClass="form-horizontal">
	<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
	<form:input path="userid" type="hidden"/>
	<form:input path="connectionid" type="hidden"/>
	<div class="form-group">
		<form:label path="venderid" cssClass="col-sm-2 control-label"><spring:message code="configration.cloud.venderName"/></form:label>
		<div class="col-sm-2">			
			<form:select path="venderid" items="${venderList }" itemLabel="venderName" itemValue="venderid" cssClass="form-control"></form:select>			
		</div>
	</div>
	<div class="form-group">
		<form:label path="accessKey" cssClass="col-sm-2 control-label">Api Key</form:label>
		<div class="col-sm-6">			
			<form:input path="accessKey" cssClass="form-control" />					
		</div>
	</div>
	<div class="form-group">
		<form:label path="secretKey" cssClass="col-sm-2 control-label">Secret Key</form:label>		
		<div class="col-sm-6"> 
			<form:input path="secretKey" cssClass="form-control"/>			
		</div>		
	</div>
	<div style="margin-top:50px;"></div> 
	<div class="form-group">
		<form:label path="connectionName" cssClass="col-sm-2 control-label">Connection Name</form:label>		
		<div class="col-sm-10">  
			<form:input path="connectionName" cssClass="form-control"/>			
		</div>
	</div>
	
	<div class="form-group">
		<form:label path="regionName" cssClass="col-sm-2 control-label">Region Name</form:label>		
		<div class="col-sm-10"> 
			<form:input path="regionName" cssClass="form-control"/>			
		</div>
	</div>
	
	<div class="form-group">
		<form:label path="zoneName" cssClass="col-sm-2 control-label">Zone Name</form:label>		
		<div class="col-sm-10"> 
			<form:input path="zoneName" cssClass="form-control"/>		
		</div>
	</div>
	
	<div class="form-group">
		<form:label path="securityGroupName" cssClass="col-sm-2 control-label">Security Group</form:label>		
		<div class="col-sm-10"> 
			<form:input path="securityGroupName" cssClass="form-control"/>		
		</div>
	</div>
	
	<div class="form-group">
		<form:label path="keyName" cssClass="col-sm-2 control-label">Key Name</form:label>		
		<div class="col-sm-10"> 
			<form:input path="keyName" cssClass="form-control"/>			
		</div>
	</div>
	
	<div class="form-group">
		<form:label path="connectionDesc" cssClass="col-sm-2 control-label">Description</form:label>		
		<div class="col-sm-10"> 
			<form:textarea path="connectionDesc" cssClass="form-control" rows="10"/>			
		</div>
	</div>
	
	<div class="form-group">
		<div class="col-sm-12 text-right">
			<button class="btn btn-default btn_link" data-link="./lists" type="button"><spring:message code="button.list"/></button>
			<c:if test="${fn:contains(buttons , Authorities.REMOVE)}">
			<button class="btn btn-primary removeBtn" type="button"><spring:message code="button.delete"/></button>
			</c:if>		
		</div>
	</div>	
</form:form>

<script type="text/javascript">
$(document).ready(function(){
	$(".form-horizontal").find(":input").attr("disabled","true");
	$(".form-horizontal").find(".btn").removeAttr("disabled");
});

$(document).on("click", ".removeBtn", function() {
	bootbox.confirm("<spring:message code='common.remove.confirm'/>", function(result) {
		if ( result ) {
			Loading.show();
			$(".form-horizontal").find(":input").removeAttr("disabled");
			$.post("./remove", $("#connectionEntityModel").serialize(), function(res) {
				
			}).fail(function() {
				bootbox.alert("<spring:message code='common.server.fail'/>"); /* 서버 통신 오류 */
			}).done(function(res) {
				if ( res ) {
					bootbox.alert("<spring:message code='common.remove.ok'/>", function() {
						Loading.link("./lists");							
					});
				} else {
					bootbox.alert("<spring:message code='common.remove.fail'/>");
				}
			}).always(function() {
				Loading.hide();
			});
		}
	});
})
</script>